#include <iostream.h>
#include <string.h>
#include <stdio.h>

	long	tot,x;

main()
{
	char	city[50];
	char	classtype[10];

//	cin>>city;
	scanf("%s",city);
	while (city[0]!='#')
	{
    	tot=0;
		while (city[0]!='0')
		{
		//	cin>>city>>x>>classtype;
			scanf("%s%d%s",city,&x,classtype);
			switch (classtype[0]) 
			{
				case 'F' :
				case 'f' : tot+=x*2; break;
				case 'B' :	
				case 'b' : tot+=x+(x+1)/2; break;
				case 'Y' :
				case 'y' : if (x<=500) tot+=500; else tot+=x; break;
			}
		//	cin>>city;
			scanf("%s",city);
		}
		printf("%ld\n",tot);
		//cin>>city;
		scanf("%s",city);
	}

	return 0;
}
